eststo clear

if("`c(os)'"=="Windows"){
	local tableSaveDir = "ReviewResponseResults\"
	local plotSaveDir = "ReviewResponseResults\"
	local pythonSaveDir = "PythonScripts\"
}
else{
	local tableSaveDir = "ReviewResponseResults/"
	local plotSaveDir = "ReviewResponseResults/"
	local pythonSaveDir = "PythonScripts/"
}

//With linear time trends
//Establish Control Variable Sets
local spec1Controls = "c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage"
local spec2Controls = "`spec1Controls' i.transactionDataDummy"
local spec3Controls = "`spec2Controls' i.regDummyExtSpec3"
local spec4Controls = "`spec2Controls' i.regDummyExtSpec4"

//Establish ci level
local ciLevel = 95

//Establish Cluster Variable
local clusterVar = "stateGroup"

//Absorb Vars are always time and state fixed effects
local absorbVars = "ib51.stateGroup ib1995.year"

//Estimate Models
//Estimate Spec. 2 DiD Model 
reghdfe logregistrations i.nosafetyind `spec2Controls', cluster(`clusterVar') absorb(`absorbVars') res(spec2Res)
eststo spec2
local df = e(N_clust)-1
addRobustFStat 1.nosafetyind
addTreat 1.nosafetyind
estadd local dsc = "Documented" 
estadd local groupFE = "Y"
estadd local timeFE = "Y"
estadd local timeTrend = "Y"
estadd local quadTimeTrend = "Y"
estadd local commonControls = "Y"
estadd local modelNum = "(2)"


//Export Model Results to TeX Files
//Establish Format
local fmtDiD = `"drop(*) nocon label compress starlevels(* 0.1 ** 0.05 *** 0.01) nodepvar nomtitle nonumbers not nostar noline"'


local noteString = "\hline \hline \end{tabular} \vspace{0.2cm} \begin{tablenotes} \begin{spacing}{0} \begin{footnotesize} \item \textbf{Notes:} This table presents difference-in-differences estimates of the impact of the removal of safety inspections on the log of vehicle registrations.  The unit of observation is state-year. The four specifications pertaining to different levels of ``Data Source Controls'' (DSCs) and control specifications are documented in Table \cref{ssec:Spec}. Standard errors, reported in parentheses, are clustered by state. * p\textless 0.1, ** p\textless 0.05, *** p\textless 0.01 \end{footnotesize} \end{spacing} \end{tablenotes} \end{table}"

//Export Table
esttab spec2 using "`tableSaveDir'RegDiDQuadraticTimeTrends.tex", `fmtDiD' title("Diff-in-Diff Results \label{tab:RegDiD}") stats(modelNum treatb treatse dsc groupFE timeFE timeTrend quadTimeTrend commonControls fStat N r2, labels("\hline \hline \multicolumn{5}{c}{Dep. Var.: Log Number of Vehicle Registrations} \\ " "Removal of" "Safety Inspections" "\makecell[l]{Data Source \nextline Controls}" "State Fixed Effects" "Year Fixed Effects" "\makecell[l]{State-Specific Linear \\ Time Trends}" "\makecell[l]{State-Specific Quadratic \\ Time Trends}" "Common Controls" "Robust F-Stat" "Number of Obs." "R\textsuperscript{2}")fmt(%8.3f %8.3f %8.3f %8.3f  %8.3f  %8.3f  %8.3f  %8.3f %8.3f %8.0fc %8.3f)) replace postfoot("`noteString'")


